<template>
	<view class="container" :style="'min-height:' +pageHei+';'">
		<view class="card-list u-flex u-flex-col u-row-center" style="padding-top: 20rpx;background-color: #F8F8F8;">
			<uni-card acWidth="700rpx" v-for="(item,index) in acList" style="margin: 0;padding: 0;">
				<view class="con-box u-flex" v-if="item.friendTypeId == 0">
					<image @click="toNavaUrl(`/pages/index/cardIndex/index?useId=${item.usrCraftsman.craftsmanId}`)" class="img-card" :src="'https://www.ydylmold.cn/images/ydylapp/usrCraftsman/image/' + (item.usrCraftsman && item.usrCraftsman.headImg)" mode=""></image>
					<view class="con-info u-flex u-flex-col u-col-top">
						<view class="title">{{item.usrCraftsman && item.usrCraftsman.usrName}}<text class="sub-title" style="font-size: 24rpx;color: #0080FF;margin-left: 10rpx;">(好友申请)</text></view>
						<text>申请时间: {{$u.timeFormat(new Date(item.createDate || Date.now()), 'yyyy-mm-dd hh:MM')}}</text>
						<view class="btn-box u-flex u-m-t-20">
							<button @click="refuseItem(item,index)" type="default" style="margin: 0;padding: 0;font-size: 24rpx;width: 200rpx;">拒绝</button>
							<button @click="agreenItem(item,index)" type="primary" style="background-color: #0080FF; margin: 0;padding: 0;font-size: 24rpx;width: 200rpx;margin-left: 20rpx;">同意</button>
						</view>
					</view>
				</view>
				<view class="con-box u-flex" v-else>
					<image @click="toNavaUrl(`/pages/index/cardIndex/compIndex?compId=${item.usrCompany.companyId}`)" class="img-card" :src="'https://www.ydylmold.cn/images/ydylapp/usrCompany/image/' + (item.usrCompany && item.usrCompany.companyLogo)" mode=""></image>
					<view class="con-info u-flex u-flex-col u-col-top">
						<view class="title">{{item.usrCompany && item.usrCompany.companyNameCn}} <text class="sub-title" style="font-size: 24rpx;color: #0080FF;margin-left: 10rpx;">(好友申请)</text></view>
						<text>申请时间: {{$u.timeFormat(new Date(item.createDate || Date.now()), 'yyyy-mm-dd hh:MM')}}</text>
						<view class="btn-box u-flex u-m-t-20">
							<button @click="refuseItem(item,index)" type="default" style="margin: 0;padding: 0;font-size: 24rpx;width: 200rpx;">拒绝</button>
							<button @click="agreenItem(item,index)" type="primary" style="margin: 0;padding: 0;font-size: 24rpx;width: 200rpx;margin-left: 20rpx;">同意</button>
						</view>
					</view>
				</view>
			
			</uni-card>
		</view>
		<my-empty tipText="还没有系统消息哦"  image="http://cdn.uviewui.com/uview/empty/data.png" v-if="isEmpty"></my-empty>
		<u-loadmore :status="status" v-else></u-loadmore>
		
	</view>
</template>

<script>
	import {
		queryFriendsApply,
		refuseApply,
		accessApply,
		updAddFriends
	} from '@/common/api/msg.js'
	import {
		getToken
	} from '@/utils/token.js'
	import {
		duplicateRemoval
	} from '@/utils/common.js'
	export default {
		data() {
			return {
				//类型选项配置
				pageHei: '100vh',
				currPage: 1,
				acList: [],
				allpage: 1,
				isEmpty: false,
				status: 'loading',
				searchText: '',
			}
		},
		onLoad: function() {
			uni.getSystemInfo({
				success: (res) => {
					this.pageHei = res.windowHeight * 2 + 'rpx'
				}
			})
			this.queryFriendsApply()
		},
		onReachBottom:function(){
			if(this.status == 'loadmore'){
				this.currPage++
				this.queryFriendsApply()
			}
		},
		methods: {
			toNavaUrl(url){
				uni.navigateTo({
					url:url
				})
			},
			refuseItem(item,index){
				uni.showModal({
					title:'提示',
					content:'您确定要拒绝该用户的好友申请吗？',
					success: (e) => {
						if(e.confirm){
							refuseApply({
								id:item.id,
								friendsType:item.friendsType
							}).then(res=>{
								if(res && res.data){
									this.$u.toast('已拒绝')
									this.acList.splice(index,1)
								}
							})
						}
					}
				})
			},
			agreenItem(item,index){
				accessApply({ //同意好友申请
					userId:item.userId,
					entity:'usrChatObjectItem',
					firendId:item.firendId,
					friendTypeId:item.friendTypeId,
					id:item.id,
					friendsType:item.friendsType
				}).then(res=>{
					if(res && res.data){
						this.acList.splice(index,1)
					}
				})
			},
			queryFriendsApply() {
				this.status = 'loading'
				queryFriendsApply({
					firendId: getToken('useNum'),
					friendsType: 0,
					status: 0,
					'page.current': this.currPage,
				}).then(res => {
					this.acList = duplicateRemoval(this.acList, res.data && res.data && res.data.rows || [],
						'id')
						//console.log("this.acList",this.acList)
					this.allpage = res.data && res.data.total
					this.currPage < this.allpage ? this.status = 'loadmore' : this.status = 'nomore'
					this.isEmpty = this.acList.length == 0 ? true : false
				})
			}
		}
	}
</script>

<style lang="scss">
	.container {
		background-color: #F8F8F8;
		.card-list{
			.con-box{
				.con-info{
					margin-left: 20rpx;
					.title{
						font-size: 35rpx;
						color: #000;
					}
				}
				.img-card{
					width: 100rpx;
					height: 100rpx;
					border-radius: 50%;
				}
			}
		}
	}
</style>
